package com.his.controller;

import com.his.annotation.RequireRoles;
import com.his.common.Const;
import com.his.common.Rsp;
import com.his.common.Temp;
import com.his.entity.ApplicantInfo;
import com.his.entity.Bed;
import com.his.service.BedService;
import lombok.NonNull;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * (Bed)表控制层
 *
 * @author makejava
 * @since 2020-10-23 18:06:00
 */
@Validated
@RestController
@RequestMapping("bed")
public class BedController {
    /**
     * 服务对象
     */
    @Resource
    private BedService bedService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @GetMapping("selectOne")
    public Rsp selectOne(@RequestHeader(Const.TOKEN) String token, Integer id) {
        return Rsp.success(this.bedService.queryById(id));
    }


    /**
     * 通过病房id查询病房下正常的所有病床信息
     *
     * @param token
     * @param wardId
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @GetMapping("selectOneByWardId")
    public Rsp selectOneByWardId(@RequestHeader(Const.TOKEN) String token, @NotBlank String wardId) {
        return Rsp.success(bedService.queryByWardId(wardId));
    }

    /**
     * 安排病床
     *
     * @param token
     * @param temp
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @PostMapping("insertBedByPatientId")
    public Rsp insertBedByPatientId(@RequestHeader(Const.TOKEN) String token, @RequestBody Temp temp) {

        return Rsp.success(bedService.insertBedByPatientId(temp));
    }

    /**
     * 调整病床
     *
     * @param token
     * @param temp
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @PostMapping("updateBedByPatientId")
    public Rsp updateBedByPatientId(@RequestHeader(Const.TOKEN) String token, @Validated(Const.Update.class) @RequestBody Temp temp) {
        return Rsp.success(bedService.updateBedByPatientId(temp));
    }


    /**
     * 更新病床信息
     *
     * @param token
     * @param bed
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @PostMapping("updateOne")
    public Rsp updateOne(@RequestHeader(Const.TOKEN) String token, @Validated(Const.Update.class) @RequestBody Bed bed) {

        return Rsp.success(bedService.update(bed));
    }

    /**
     * 插入病床信息
     *
     * @param token
     * @param bed
     * @return
     */
    @RequireRoles(roles = {"nurse"}, index = 0)
    @PostMapping("insertOne")
    public Rsp insertOne(@RequestHeader(Const.TOKEN) String token, @RequestBody Bed bed) {
        return Rsp.success(bedService.insert(bed));
    }

}
